<?php

class Article_Collection extends Collection
{
	public function Article_Collection()
	{
		parent::Collection("article", "id");
	}
	
	public function getByUrl($str)
	{
		$sql = new SQLAdapt();
		$req = "select * from article where url_title = '$str'";
		$res = $sql->query($req);
		$res = $res->fetch();
					
		if($res != null)
		{
			$constructeur = "Cl_article_Modele::getRef";
			// On construit la liste des param�tres
			for($i=0;$i<$this->_nbField;$i++)
				$param[$i] = $res[$i];
			// On construit l'occurence
			$occurence = call_user_func_array($constructeur, $param);
			return $occurence;
		}
		else
			return null;
	}
	
	public function getNbArticle($id = null)
	{
		$sql = new SQLAdapt();
		if($id != null)
			$req = "select count(id) as nb from article where isPublished = 1 and categorie = $id";
		else
			$req = "select count(id) as nb from article where isPublished = 1";
		$res = $sql->query($req);
		$res = $res->fetch();
		return $res[0];
		
	}

}

?>
